<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class StatisticSite extends ActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	public function tableName()
	{
		return 'vh_statistic_site';
	}
	
	public function rules()
	{
		return array(
		);
	}

	public function search()
	{
		$condition = "";
		
                if(!empty($_POST['domain']))
			$condition .= " AND domain LIKE '%" . $_POST['domain'] . "%'";
                
		if(!empty($_POST['planTime']))
			$condition .= " AND planTime = '" . $_POST['planTime'] . "'";
		
		if(!empty($_POST['monitor']))
			$condition .= " AND monitor = '" . $_POST['monitor'] . "'";
                
		if(!empty($_POST['adv']))
			$condition .= " AND adv = '" . $_POST['adv'] . "'";
		
		if(!empty($_POST['payment']))
			$condition .= " AND payment = '" . $_POST['payment'] . "'";
		
		if(!empty($_POST['feature']))
			$condition .= " AND feature = '" . $_POST['feature'] . "'";
		
		if(!empty($_POST['lifeTime']))
			$condition .= " AND lifeTime = '" . $_POST['lifeTime'] . "'";
		
		$query = "SELECT * 
			FROM vh_statistic_site
			WHERE 1 = 1 $condition
                        ORDER BY createdDate DESC
                ";
		
		$result = $this -> executeAllTotal($query);
	
		return $result;
	}
        
        public function updateLifeTime($id)
	{		
            $query = "
                UPDATE vh_statistic_site 
                SET lifeTime = IF(endDate IS NULL,DATEDIFF(now(), startDate),DATEDIFF(endDate, startDate))
                WHERE id = $id
            ";
            
            $result = $this ->executeNone($query);
		
            return true;
	}    
}